<template>
	<view class="box">
		<!-- <view class="back"></view> -->
		<!-- <view class="top textOver">
			拼团时间剩余00:14:59,请尽快邀请好友参与哦
		</view> -->
		<view class="cont">
			<!-- <view class="head">
				<text class="textOver" style="font-size: 35rpx;">香满楼东企鹅</text>
				<view class="right">
					<text>进店逛逛</text>
					<image class="icon_next" src="../../static/images/mine/icon_next.png" mode=""></image>
				</view>
			</view> -->
			<view class="line"></view>
			<view class="contBot" style="display: block;">
				<view class="leftImg">
					<image :src="item.hasPlot == 1 ? snapshot[0].avatar : snapshot.img" mode="aspectFill"></image>
				</view>
				<view class="rightCont">
					<view class="textOver" style="font-size: 35rpx;">{{item.hasPlot == 1 ? snapshot[0].title : snapshot.title}}</view>
					<view class="person textOver" ><text >{{item.hasPlot == 1 ? snapshot[0].overview : snapshot.specName}}</text></view>
					<view class="contPrice">
						<view class="price">
							<text :class="item.hasRealUnit?'':'noLine'">
								￥{{item.hasPlot==1? item.snapshot[0].standardPrice : item.unitPrice}}
							</text>
							<text class="littleMon origin"
							v-if="item.snapshot.originPrice && item.unitPrice != item.snapshot.originPrice && item.hasPlot != 1">
								￥{{item.snapshot.originPrice}}
							</text>
						</view>
						<!-- <view class="bulkPrice" v-if="item.hasRealUnit">
							拼单价￥<text>{{item.realUnitPrice}}</text></view> -->
					</view>
					<text class="num">x{{item.hasPlot==1? item.snapshot[0].amount : item.count}}</text>
				</view>
				<view class="line" style="margin: 25rpx 0 20rpx;"></view>
				<view class="bottomPrice">
					<view class="total">
						合计:
						<text class="littleMon">￥</text>
						<text>{{item.realPrice}}</text>

					</view>
					<rich-text style="font-size: 32rpx;" :nodes="getStatus(order.status)"></rich-text>
				</view>
			</view>
		</view>
		<!-- <view class="bulkPerson">
			<view class="head"><text>3</text>人成团,当前有<text>2</text>人参团</view>
			<view class="line" style="margin: 20rpx 0;"></view>
			<view class="img">
				<image src="../../static/images/growVegetables/pay_icon.png" mode=""></image>
				<image src="../../static/images/growVegetables/pay_icon.png" mode=""></image>
				<view class="block">+</view>
			</view>
		</view> -->
		<view class="cont" v-if="item.qrCode && status != -1">
			<view class="head">
				<text class="textOver" style="font-size: 35rpx;">核销二维码</text>
			</view>
			<view class="line"></view>
			<view class="contBot" style="flex-direction: column;align-items: center;">
				<view>请向商家出示二维码</view>
				<image class="codeImg" :src="item.qrCode" mode="aspectFill"></image>
			</view>
		</view>
		<view class="cont">
			<view class="head">
				<text class="textOver" style="font-size: 35rpx;">商家信息</text>
			</view>
			<view class="line"></view>
			<view class="contBot">
				<view class="left-content">
					<view class="text">电话: {{phone}}</view>
					<view class="text">{{item.hasPlot==1? '土地名称' : '店铺名称'}}: {{storeName}}</view>
				</view>
				<view class="detailsBoxRight">
					<button type="primary" @tap="callphone" plain size="mini">致电</button>
				</view>
			</view>
		</view>
		<view class="cont">
			<view class="head">
				<text class="textOver" style="font-size: 35rpx;">订单信息</text>
			</view>
			<view class="line"></view>
			<view class="contBot" style="">
				<view class="left-content">
					<view class="text">订单编号: {{item.orderNum}}</view>
					<view class="text">创建时间: {{params.createTime}}</view>
					<!-- <view class="text">配送方式: {{}}</view> -->
				</view>
				<view class="detailsBoxRight" style="display: inline-block;">
					<button type="primary" @tap="copyBtn(item.orderNum)" plain size="mini" class="btnCopy">复制</button>
				</view>
			</view>
		</view>

		<!--  -->
		<view class=" cont" v-if="item.status==0">
			<view class="between head">
				<text style="font-size: 35rpx;">支付方式</text>
			</view>
			<view class="line"></view>
			<radio-group name="pay" @change="payWay" style="padding: 0 24rpx;">
				<view class="plotAddressBorder between3" style="margin-top: 0;">
					<view class="center_vertical">
						<view>
							<image src="../../static/images/growVegetables/pay_icon.png" class="icon"></image>
						</view>
						<view>
							微信支付
						</view>
					</view>
					<view>
						<radio value="wechat" />
					</view>
				</view>
				<view class="plotAddressBorder between3">
					<view class="center_vertical">
						<view>
							<image src="../../static/images/growVegetables/wallet_icon.png" class="icon">
							</image>
						</view>
						<view>
							余额支付
						</view>
					</view>
					<view>
						<radio value="balance" />
					</view>
				</view>
			</radio-group>
		</view>
		
		<button class="paybtn2" v-if="item.status==0 " @click="pay(item.orderNum)" type="primary">立即支付</button>
		<button class="paybtn2" v-else-if="item.status==3"  type="primary" @click="goEval">立即评价</button>
		<button class="paybtn2" v-else  type="primary" open-type="share">分享</button>
		<!-- v-else-if="item.status==3" -->

	</view>
</template>

<script>
	import cartcontrol from '@/components/cartcontrol.vue'
	import Skeleton from '@/components/ls-skeleton/ls-skeleton.nvue';
	import hqsPopup from "@/components/hqs-popup/hqs-popup.vue"
	import {
		getTime
	} from "@/utils/auth.js"
  import SOtime from '../../js_sdk/fl-SOtime/SOtime.js'
	export default {
		components: {
			cartcontrol,
			Skeleton,
			hqsPopup,
			imgapi: "",
			payMode: "", //支付方式
			order: {},
		},
		data() {
			return {
				duration: 500,
				item: {},
				snapshot: {},
				address: {},
				phone: "",
				storeName: "",
				order: {},
				params:{},
				imgapi:"",
			}
		},
		onLoad(e) {
			const {
					item = {}
				} = e;
			this.item = JSON.parse(decodeURIComponent(item));
			
			console.log("this.item",this.item);
			
			this.imgapi = this.$reqConfig.URLIMAGE
			this.snapshot = this.item.snapshot
			
			if(this.item.hasPlot != 1){
				this.$axios({
					url: `user/usGroupGoodsOrder/orderDetail`,
					method: "post",
					data: {
						orderNum: this.item.orderNum
					}
				}).then((res) => {
					console.log('res', res);
					let obj = res.result
					this.phone = obj.phone
					this.storeName = obj.storeName
					this.order = obj.order
					this.params = {
						...this.params,
						phone:obj.phone,
						storeName:obj.storeName,
						createTime:SOtime.time3(this.order.createTime),
					}
				})
			}else{
				this.$axios({
					url: `user/plot/plotDetail`,
					method: "post",
					data: {
						id: this.item.plotId
					}
				}).then((res) => {
					let obj = res.result
					this.phone = obj.phone
					this.storeName = obj.plotName
					
					this.params = {
						...this.params,
						phone:obj.phone,
						storeName:obj.storeName,
						createTime:SOtime.time3(this.order.createTime),
					}
				})
			}
			
		},
		methods: {
			getStatus(status) {
				switch (status) {
					case 0:
						return '<font style="color: #90d028;">待支付</font>'
					case 1:
						return '<font style=" color: #90d028;">已支付</font>'
					case 2:
						return '<font style="color: #90d028;">拼团成功</font>'
					case 3:
						return '<font style="color: #90d028;">已发货</font>'
					case 4:
						return '<font style="color: #90d028;">已评价</font>'
					case -1:
						return '<font style="color: #90d028;">已取消</font>'
				}
			},
			// 评价页
			goEval(){
				console.log(111);
				uni.navigateTo({
					url: `./eval?order=${JSON.stringify(this.order)}&type=4`
				});
				
			},
			//单选事件
			payWay(e) {
				this.payMode = e.detail.value
			},
			//支付订单
			pay(orderNum) {
				if (!this.payMode) {
					uni.showToast({
						title: "请选择支付方式",
						icon: 'none',
						duration: 2000
					})
					return;
				}
				//成功提交执行对应操作
				if (this.payMode == "balance") {
					uni.showLoading({
						title: "余额支付中......"
					})

					this.balancePay(orderNum)

					//半秒缓冲，等到后端状态修改完成跳转
					setTimeout(function() {
						uni.hideLoading()
						//跳转到订单列表
						uni.redirectTo({
							url: './bulkOrder'
						})
					}, 600);
				} else {
					console.log("微信支付")
				}
			},
			// 余额支付
			balancePay(orderNum) {
				this.$axios({
					url: `user/usGroupGoodsOrder/balancePay`,
					method: "post",
					data: {
						orderNum
					}
				}).then((res) => {
					if (res.code == 0) {
						uni.showToast({
							title: "支付成功!",
							icon: 'none',
							duration: 2000
						})
					}
				})
			},
			// 打电话
			callphone() {
				uni.makePhoneCall({
					phoneNumber: this.phone //仅为示例
				});
			},


			// 复制
			copyBtn(value) {
				console.log(value);
				uni.setClipboardData({
					data: value,
					success: function() {
						uni.showToast({
							title: '复制成功',
							duration: 2000,
							icon: 'none'
						});
					},
					fail: function(err) {
						uni.showToast({
							title: '复制失败',
							duration: 2000,
							icon: 'none'
						});
					}
				});
			}
		}
	}
</script>

<style scoped>
	.origin{
		margin-left: 10rpx;
		color: #b3b3b3;
		text-decoration: line-through;
	}
	.codeImg {
		border: 2rpx solid #eee;
		width: 350rpx;
		height: 350rpx;
		margin: 30rpx;
	}

	.orderListbox3 {
		margin: 20rpx 0 30rpx;
		width: 660rpx;
		background-color: #fff;
		border-radius: 20rpx;
		height: 280rpx;
		padding: 20rpx;
	}

	.icon {
		width: 50rpx;
		height: 50rpx;
		margin-right: 20rpx;
		margin-top: 10rpx;
	}

	.plotAddressBorder {
		width: 100%;
		/* background-color: #000000; */
		margin-top: 20rpx;
		padding-top: 20rpx;
		border-bottom: 0.5rpx solid #eeeeee;
		display: flex;
		justify-content: space-between;
	}

	/deep/ .between3.data-v-16353827 {
		width: 100%;
	}

	.paybtn2 {
		background-color: #18BC37;
		margin: 20rpx 0;
	}

	.box {
		padding: 30rpx;
	}

	.btnCopy {
		width: 149rpx;
		height: 50rpx;
		line-height: 50rpx;
		border-radius: 100rpx;
		font-size: 30rpx;
		padding-bottom: 50rpx;
	}

	/* .back {
		position: absolute;
		z-index: -1;
		background-color: #86cc14;
		height: 600rpx;
		width: 100%;
		top: 0;
		left: 0;
		border-radius: 0 0 235rpx 116rpx;
	} */

	.cont {
		background-color: #FFFFFE;
		border-radius: 25rpx;
		overflow: hidden;
		margin-bottom: 30rpx;

	}

	.cont .head {
		padding: 18rpx 24rpx;
		font-weight: 700;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.cont .head .right {
		font-size: 30rpx;
		font-weight: normal;
	}

	.cont .head image {
		width: 30rpx;
		height: 30rpx;
		vertical-align: middle;
	}

	.line {
		height: 3rpx;
		background-color: #eee;
	}

	.cont .contBot {
		padding: 0 30rpx;
		display: flex;
		justify-content: space-between;
		padding: 18rpx 24rpx;
	}

	.contBot .leftImg {
		width: 150rpx;
		height: 150rpx;
		border-radius: 15rpx;
		overflow: hidden;
		position: absolute;
		border: 2rpx solid #eee;
	}

	.contBot .leftImg image {
		width: 100%;
		height: 100%;
	}

	.contBot .leftImg text {
		display: inline-block;
		color: #FFFFFE;
		background-color: #86cc14;
		position: absolute;
		top: -2px;
		left: 0px;
		font-size: 25rpx;
		padding: 0rpx 10rpx;
	}


	.contBot .rightCont {
		margin-left: 175rpx;
	}

	.contBot .rightCont .person {
		color: #aaaaaa;
		font-size: 30rpx;
		margin-bottom: 8rpx;
		height: 50rpx;
	}

	.contBot .rightCont .contPrice {}

	.rightCont .contPrice .price {
		color: #aaaaaa;
		font-size: 25rpx;
		display: inline-block;
	}

	.rightCont .contPrice .price .noLine {
		text-decoration: none;
	}


	.rightCont .contPrice .price text {
		color: #ff7800;
		font-weight: bold;
		text-decoration: line-through;
		font-size: 38rpx;
		margin-right: 10rpx;
	}

	.rightCont .contPrice .bulkPrice {
		font-size: 26rpx;
		background: #86cc14;
		color: #fff;
		text-align: center;
		border-radius: 15rpx;
		display: inline-block;
		margin-left: 15rpx;
		padding: 5rpx 10rpx;
	}

	.num {
		float: right;
		margin-top: -34rpx;
		color: #cccccc;
		font-size: 30rpx;
	}

	.rightCont .contPrice .bulkPrice text {
		font-size: 40rpx;
		font-weight: bold;
	}

	.bottomPrice {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 10rpx;
	}

	.total {
		font-size: 36rpx;
	}

	.total text {
		color: #ff7800;
		font-weight: bold;
		margin-left: 5rpx;
	}

	.tit {
		font-size: 32rpx;
	}

	.bulkPerson {
		background: #fff;
		padding: 20rpx 30rpx;
		border-radius: 20rpx;
		margin-bottom: 30rpx
	}

	.bulkPerson .head {
		font-size: 35rpx;
		font-weight: bold;
	}

	.bulkPerson .head text {
		color: #87cc16;
	}

	.detailsBoxRight {
		width: 25%;
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		justify-content: center;
	}

	.bulkPerson image {
		width: 70rpx;
		height: 70rpx;
		margin-right: 25rpx;
		vertical-align: bottom;
		border: 2rpx solid #eee;
		border-radius: 50%;
	}

	.top {
		text-align: center;
		font-size: 30rpx;
		background: #f5ffe6;
		margin-bottom: 35rpx;
		height: 90rpx;
		line-height: 90rpx;
		color: #86cc14;
		border-radius: 30rpx;
	}

	.block {
		display: inline-block;
		width: 70rpx;
		height: 70rpx;
		color: #cccccc;
		background: #eeeeee;
		text-align: center;
		line-height: 70rpx;
		border-radius: 50%;
		border: 2rpx dashed;
		box-sizing: border-box;
	}

	.left-content {
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		width: 450rpx;
	}

	.left-content .text {
		font-size: 30rpx;
		color: #a3a3a3;
	}
</style>
